package com.example.simple.work.controller;

import com.example.simple.work.entity.Facility;
import com.example.simple.work.service.IFacilityService;
import com.example.simple.work.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("facility")
public class FacilityController extends BaseController{
    @Autowired
    private IFacilityService facilityService;

    /** 添加设备登记信息 */
    @RequestMapping("/insert")
    public JsonResult<Void> insert (Facility facility){
        facilityService.insert(facility);
        return new JsonResult<>(OK);
    }

    /** 根据id删除设备登记信息 */
    @RequestMapping("delete")
    public JsonResult<Void> delete (Integer id){
        facilityService.delete(id);
        return new JsonResult<>(OK);
    }

    /** 查询所有设备登记信息 */
    @RequestMapping("list")
    @CrossOrigin
    public JsonResult<List<Facility>> list (){
        List<Facility> list = facilityService.findAllFacility();
        return new JsonResult<>(200,list);
    }

    /** 根据id查询设备登记信息 */
    @RequestMapping("select")
    public JsonResult<Facility> select (Integer id){
        Facility data = facilityService.findById(id);
        return new JsonResult<>(OK,data);
    }

}